﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using Autodesk.Revit.UI;
using YJKRevitFamilyDataBase;
using YJKExcelFormTool.DataDefine;

namespace YJKExcelFormTool.Forms
{
	public partial class TestMaterialInterfaceForm : System.Windows.Forms.Form
	{
		public ImportMaterialTableInfos TheTableInfos
		{
			get
			{
				return this.m_TableInfos;
			}
		}

		public string ProgramName()
		{
			return this.lbProgramList.GetItemText(this.lbProgramList.SelectedItem);
		}

		public string ProgramId()
		{
			return this.m_ProgramIdList[this.lbProgramList.SelectedIndex];
		}

		public TestMaterialInterfaceForm(ExternalCommandData cmdData, MaterialProgramInfos._Tag_TemplateType templateType)
		{
			this.m_Revit = cmdData;
			this.m_TemplateType = templateType;
			this.InitializeComponent();
		}

		private void TestMaterialInterfaceForm_Load(object sender, EventArgs e)
		{
			if (this.m_TemplateType == MaterialProgramInfos._Tag_TemplateType.TT_EXCEL)
			{
				this.btnDrawing.Visible = false;
			}
			else
			{
				this.btnExplort.Visible = false;
			}
			this.UpdateProgramInfoList();
			if (this.lbProgramList.Items.Count > 0)
			{
				this.lbProgramList.SelectedIndex = 0;
			}
		}

		private void btnAdd_Click(object sender, EventArgs e)
		{
			string text = "";
			TableInterface.AddMaterialTableProgram(this.m_Revit, SubjectType.Electric, this.m_TemplateType, ref text);
			this.UpdateProgramInfoList();
			this.lbProgramList.SelectedIndex = this.lbProgramList.Items.Count - 1;
		}

		private void btnEdit_Click(object sender, EventArgs e)
		{
			int selectedIndex = this.lbProgramList.SelectedIndex;
			if (selectedIndex < 0)
			{
				return;
			}
			string text = "";
			TableInterface.EditMaterialTableProgram(this.m_Revit, this.ProgramName(), this.ProgramId(), SubjectType.Electric, this.m_TemplateType, ref text);
			this.UpdateProgramInfoList();
			this.lbProgramList.SelectedIndex = selectedIndex;
		}

		private void btnRemove_Click(object sender, EventArgs e)
		{
			if (this.lbProgramList.SelectedIndex < 0)
			{
				return;
			}
			TableInterface.RemoveProgram(SubjectType.Electric, this.ProgramName(), this.ProgramId(), this.m_Revit);
			this.UpdateProgramInfoList();
			if (this.lbProgramList.Items.Count > 0)
			{
				this.lbProgramList.SelectedIndex = this.lbProgramList.Items.Count - 1;
			}
		}

		private void btnDrawing_Click(object sender, EventArgs e)
		{
			if (this.lbProgramList.SelectedIndex < 0)
			{
				return;
			}
			string text = "";
			List<CombinationOfAttributes> combinationOfAttributesList = new List<CombinationOfAttributes>();
			List<MaterialProgramInfos.FilterType> filterTypeList = new List<MaterialProgramInfos.FilterType>();
			List<string> selectedCategoryNameList = new List<string>();
			TableInterface.GetStatisticsDetailsWithMaterialTable(SubjectType.Electric, this.m_Revit, this.ProgramName(), this.ProgramId(), ref selectedCategoryNameList, ref combinationOfAttributesList, ref filterTypeList, ref text);
			this.m_TableInfos = this.CreateTestData(selectedCategoryNameList, combinationOfAttributesList, filterTypeList);
		}

		private void btnExplort_Click(object sender, EventArgs e)
		{
			if (this.lbProgramList.SelectedIndex < 0)
			{
				return;
			}
			string text = "";
			List<CombinationOfAttributes> combinationOfAttributesList = new List<CombinationOfAttributes>();
			List<MaterialProgramInfos.FilterType> filterTypeList = new List<MaterialProgramInfos.FilterType>();
			List<string> selectedCategoryNameList = new List<string>();
			TableInterface.GetStatisticsDetailsWithMaterialTable(SubjectType.Electric, this.m_Revit, this.ProgramName(), this.ProgramId(), ref selectedCategoryNameList, ref combinationOfAttributesList, ref filterTypeList, ref text);
			this.m_TableInfos = this.CreateTestData(selectedCategoryNameList, combinationOfAttributesList, filterTypeList);
		}

		private ImportMaterialTableInfos CreateTestData(List<string> selectedCategoryNameList, List<CombinationOfAttributes> combinationOfAttributesList, List<MaterialProgramInfos.FilterType> filterTypeList)
		{
			ImportMaterialTableInfos importMaterialTableInfos = new ImportMaterialTableInfos(SubjectType.Electric);
			for (int i = 0; i < 5; i++)
			{
				List<ImportTableCell> list = new List<ImportTableCell>();
				ImportTableCell item = new ImportTableCell(_Tag_ImportCellValueType.CVT_STRING, "序号", (i + 1).ToString());
				list.Add(item);
				ImportTableCell item2 = new ImportTableCell(_Tag_ImportCellValueType.CVT_STRING, "导线类型", "wire1");
				list.Add(item2);
				ImportTableCell item3 = new ImportTableCell(_Tag_ImportCellValueType.CVT_STRING, "截面", (i + 1).ToString() + "mm");
				list.Add(item3);
				ImportTableCell item4 = new ImportTableCell(_Tag_ImportCellValueType.CVT_STRING, "数量长度", (i * 10 + 1).ToString());
				list.Add(item4);
				ImportTableCell item5 = new ImportTableCell(_Tag_ImportCellValueType.CVT_STRING, "单位", "米");
				list.Add(item5);
				ImportTableCell item6 = new ImportTableCell(_Tag_ImportCellValueType.CVT_STRING, "备注", "火线");
				list.Add(item6);
				ImportTableRow row = new ImportTableRow("导线", list);
				importMaterialTableInfos.AddTableRecord(row);
			}
			for (int i = 0; i < 5; i++)
			{
				List<ImportTableCell> list2 = new List<ImportTableCell>();
				ImportTableCell item7 = new ImportTableCell(_Tag_ImportCellValueType.CVT_STRING, "序号", (i + 6).ToString());
				list2.Add(item7);
				ImportTableCell item8 = new ImportTableCell(_Tag_ImportCellValueType.CVT_STRING, "桥架类型", "CraneSpan1");
				list2.Add(item8);
				int num = i + 1;
				ImportTableCell item9 = new ImportTableCell(_Tag_ImportCellValueType.CVT_STRING, "宽度", num.ToString());
				list2.Add(item9);
				ImportTableCell item10 = new ImportTableCell(_Tag_ImportCellValueType.CVT_STRING, "高度", num.ToString());
				list2.Add(item10);
				ImportTableCell item11 = new ImportTableCell(_Tag_ImportCellValueType.CVT_STRING, "数量长度", (i * 10 + 1).ToString());
				list2.Add(item11);
				ImportTableCell item12 = new ImportTableCell(_Tag_ImportCellValueType.CVT_STRING, "单位", "个");
				list2.Add(item12);
				ImportTableCell item13 = new ImportTableCell(_Tag_ImportCellValueType.CVT_STRING, "备注", "");
				list2.Add(item13);
				ImportTableRow row2 = new ImportTableRow("桥架", list2);
				importMaterialTableInfos.AddTableRecord(row2);
			}
			return importMaterialTableInfos;
		}

		private void UpdateProgramInfoList()
		{
			this.lbProgramList.Items.Clear();
			this.m_ProgramIdList.Clear();
			bool isExcelTemplate = false;
			if (this.m_TemplateType == MaterialProgramInfos._Tag_TemplateType.TT_EXCEL)
			{
				isExcelTemplate = true;
			}
			foreach (MaterialProgramInfos.BasicInfo basicInfo in TableInterface.GetProgramInfoList(SubjectType.Electric, isExcelTemplate, this.m_Revit))
			{
				this.lbProgramList.Items.Add(basicInfo.m_Name);
				this.m_ProgramIdList.Add(basicInfo.m_Id);
			}
		}

		private ExternalCommandData m_Revit;

		private ImportMaterialTableInfos m_TableInfos;

		private MaterialProgramInfos._Tag_TemplateType m_TemplateType;

		private List<string> m_ProgramIdList = new List<string>();
	}
}
